//
//  DSPStatusToolBar.swift
//  SWweibo
//
//  Created by 杜守鹏 on 16/1/4.
//  Copyright © 2016年 杜守鹏. All rights reserved.
//

import UIKit

class DSPStatusToolBar: UIView {
    
    private var retweetBtn: UIButton!
    private var commentBtn: UIButton!
    private var attitudeBtn: UIButton!
    
    var statusViewModel:DSPStatusViewModel?{
        didSet{
            retweetBtn.setTitle(statusViewModel?.repostsCount, forState: .Normal)
            commentBtn.setTitle(statusViewModel?.commentsCount, forState: .Normal)
            attitudeBtn.setTitle(statusViewModel?.attitudesCount, forState: .Normal)
            
        }
    }
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    //MARK:setupUI
    func setupUI(){
      // 添加三个按钮
        retweetBtn = addChildButton("转发", imageName: "timeline_icon_retweet")
        commentBtn = addChildButton("评论", imageName: "timeline_icon_comment")
        attitudeBtn = addChildButton("赞", imageName: "timeline_icon_unlike")
        let sp1 = addSpliteView()
        let sp2 = addSpliteView()
        
        // 转发按钮
        retweetBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(self)
            make.top.equalTo(self)
            make.bottom.equalTo(self)
            make.width.equalTo(commentBtn.snp_width)
        }
        
        // 评论按钮
        commentBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.top.equalTo(retweetBtn)
            make.bottom.equalTo(retweetBtn)
            make.width.equalTo(attitudeBtn.snp_width)
        }
        // 评论
        attitudeBtn.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentBtn.snp_trailing)
            make.trailing.equalTo(self)
            make.top.equalTo(commentBtn)
            make.bottom.equalTo(commentBtn)
        }
        
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
    }
    
    //MARK:创建button
    func addChildButton(title:String, imageName:String)->UIButton{
        let button = UIButton()
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: UIControlState.Normal)
        button.titleLabel?.font = UIFont.systemFontOfSize(14)
        button.setTitleColor(UIColor.darkGrayColor(), forState: .Normal)
        button.setImage(UIImage(named: imageName), forState: .Normal)
        button.setTitle(title, forState: .Normal)
        addSubview(button)
        return button
    }
    
    //MARK:创建分割线
    func  addSpliteView()->UIView{
        let imageView = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(imageView)
        return imageView
    }
    
}
